yjx.controller('reservationController',['$rootScope','$scope','$stateParams','$fetch','modalService','$timeout',function ($rootScope,$scope,$stateParams,$fetch,modalService,$timeout) {
    var productId = $stateParams.id;
    var clientListApi='/customer/list';
    var reserveId;
    /*获取客户列表*/
    function getClientList() {
        $fetch.fetch(
            clientListApi,
            {
                params:{
                },
                cache:false,
            }
        ).then(function (data) {
                $timeout(function(){
                    if(data) {
                        $scope.reservationList = data
                    }
                })
            }).catch(function (e) {
                modalService.mainMsgError(e.msg);
            })
    }
    getClientList();

    /*选择客户*/
    
    $scope.onClick = function (item) {
      for(var i=0;i<$scope.reservationList.length;i++){
          $scope.reservationList[i].checkit = false;
      }
      item.checkit = true;
      reserveId = item.id;
    }
    /*点击预约*/
    $scope.reservation = function() {
        if(reserveId) {
            /*调接口*/
            $fetch.fetch(
                '/bespeak/product',
                {
                    params:{
                        customerId:reserveId,
                        productId:productId,
                    },
                    type:'post',
                    cache:false
                }
            ).then(function(data){
                    history.back();
                    modalService.mainMsgInfo("待办事项中将出现这些提醒",'','预约成功')
                }).catch(function(e){
                    modalService.mainMsgError(e.msg);
                })
        }
    }

}])


